package Year21_Month11.day1103;

import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

public class Solution {
    public List<List<Integer>> levelOrder(TreeNode root) {
        List<List<Integer>> list = new ArrayList();
        if (root == null) {
            return null;
        }
        Queue<TreeNode> queue = null;
        queue.offer(root);
        while (queue != null) {
            List<Integer> list2 = new ArrayList();
            int a = queue.size();
            for (int i = 0; i < a; i++) {
                if (queue.peek().left != null) {
                    queue.offer(queue.peek().left);
                }
                if (queue.peek().right != null) {
                    queue.offer(queue.peek().right);
                }
                list2.add(queue.poll().val);
            }
            list.add(list2);
        }
        return list;
    }
}
